package k8ssvc

import (
	corev1 "gluenet/internal/agent/api/core/v1"
	"gluenet/internal/agent/driver/k8sdriver/option"
)

func (svc *Service) ListContainers(meta *corev1.GluenetMeta) (resp corev1.CommonResp) {
	// TODO: namespace存在性判断
	cts, err := svc.kd.ListPods(meta.GluenetGuid, option.ListOptions{}).ContainerList()

	if err != nil {
		svc.logger.Errorf(err.Error())
		resp = corev1.NewCommonFailureResp(err.Error())
	} else {
		resp = corev1.NewCommonSuccessRespWithData(corev1.GluenetAppInstance{
			GluenetMeta: *meta,
			Spec: corev1.App{
				Containers: cts,
			},
		})

	}
	return
}
